'/
' GUI Library
' Written by Anton Berlin, 2010.
' 
' =========================================================================
' 
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License as published
' by the Free Software Foundation; either version 3 of the License.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU Lesser General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'/

superstrict

import "GUI_Gadget.bmx"

type GUI_Image extends GUI_Gadget

	'// -------------------------------------------------------------------------------------------------------------
	'// Draw this gadget.
	'// -------------------------------------------------------------------------------------------------------------
	method draw()
	
		if (not m_visible or not m_image) ..
			return;
		
		'// Setup the default drawing settings.
		drawutil.setColorInit(m_primitiveR, m_primitiveG, m_primitiveB);
		drawutil.setAlphaInit(m_transparency);
		drawutil.setFontInit(null);
		
		'// Draw the primitive of the gadget.
		drawRect(m_posX, m_posY, m_width, m_height);
		
		'// Draw the design of the gadget.
		design();
		
		'// Reset drawing settings.
		drawutil.resetColor();
		drawutil.resetAlpha();
		drawutil.resetFont();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Draw the design of this gadget.
	'// -------------------------------------------------------------------------------------------------------------
	method design()
	
		if (not m_image) ..
			return;
		
		'// Shadow.
		if (m_useSurroundingShadows) ..
			drawSurroundingShadow();
		
		setColor(255, 255, 255);
		
		if (m_stretchToEdges) ..
			drawImageRect(m_image, m_posX, m_posY, m_width, m_height); ..
		else ..
			drawSubImageRect(m_image, m_posX, m_posY, m_width, m_height, 0, 0, m_width, m_height);
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use a window title.
	'// -------------------------------------------------------------------------------------------------------------
	method setImage(image:TImage)
	
		m_image = image;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not the image should stretch to the edges, making it smaller, or bigger, if necessary.
	'// -------------------------------------------------------------------------------------------------------------
	method setStretchToEdges(value:byte)
	
		m_stretchToEdges = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The font to use on the title text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_image:TImage;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Stretch the image to the edges of the gadget, making it smaller, or bigger, if necessary.
	'// -------------------------------------------------------------------------------------------------------------
	field m_stretchToEdges:byte = true;

end type

